<template>
  <div>
    <a-button @click="downLoad">下载</a-button>
  </div>
</template>
<script>
export default {
  data() {
    return {
      url: "https://img1.baidu.com/it/u=4215781871,595897871&fm=253&app=120&size=w931&n=0&f=JPEG&fmt=auto?sec=1698771600&t=1be671627b19c84894c11992ec524641",
    };
  },
  created() {},
  mounted() {},
  methods: {
    downLoad() {
      var url = this.url; // 获取图片地址
      var a = document.createElement("a"); // 创建一个a节点插入的document
      var event = new MouseEvent("click"); // 模拟鼠标click点击事件
      a.download = "aaPic.jpg"; // 设置a节点的download属性值
      a.href = url; // 将图片的src赋值给a节点的href
      a.dispatchEvent(event); // 触发鼠标点击事件
    },
  },
  components: {},
};
</script>
